from django.db import models
import uuid

class FinanceChatHistory(models.Model):
    """财务助手聊天历史记录模型"""
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    user_id = models.CharField(max_length=100, verbose_name="用户ID")
    prompt = models.TextField(verbose_name="用户提问")
    ai_response = models.TextField(verbose_name="AI回答")
    created_at = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    updated_at = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        verbose_name = "财务聊天记录"
        verbose_name_plural = "财务聊天记录"
        ordering = ["-created_at"]  # 按创建时间倒序排列

    def __str__(self):
        return f"{self.user_id} - {self.created_at.strftime('%Y-%m-%d %H:%M')}"